<template include="./view/htm/common.header.htm">
	<slot name="body">
        <div class="card-body bg-white px-0 py-5">
			<div class="row line-height-4 m-0">
				<div class="col-lg-6 mx-auto">
					<form action="<?php echo url('my-password');?>" method="post" id="form">
						<div class="form-group input-group">
							<div class="input-group-prepend">
								<span class="input-group-text"><i class="icon-lock"></i></span>
							</div>
							<input type="password" class="form-control" id="password_old" name="password_old" placeholder="<?php echo lang('password_old');?>" required>
							<div class="invalid-feedback"></div>
						</div>

						<div class="form-group input-group">
							<div class="input-group-prepend">
								<span class="input-group-text"><i class="icon-lock"></i></span>
							</div>
							<input type="password" class="form-control" id="password_new" name="password_new" placeholder="<?php echo lang('password_new');?>" required>
							<div class="invalid-feedback"></div>
						</div>

						<div class="form-group input-group">
							<div class="input-group-prepend">
								<span class="input-group-text"><i class="icon-lock"></i></span>
							</div>
							<input type="password" class="form-control" id="password_new_repeat" name="password_new_repeat" placeholder="<?php echo lang('password_new_repeat');?>" required>
							<div class="invalid-feedback"></div>
						</div>
						<div>
							<button type="submit" class="btn btn-primary btn-block" id="submit" data-loading-text="<?php echo lang('submiting');?>...">
								<?php echo lang('update_password');?>
							</button>
						</div>
					</form>
				</div>
			</div>
		</div>
	</slot>
</template>

<script src="<?php echo view_path();?>js/md5.js"></script>
<script>
	var body = $('body');
	body.on('submit', '#form', function () {
		var jthis = $(this);
		var jsubmit = jthis.find('#submit');
		jsubmit.button('loading');
		jthis.reset();
		var postdata = jthis.serializeObject();
		postdata.password_old = $.md5(postdata.password_old);
		postdata.password_new = $.md5(postdata.password_new);
		postdata.password_new_repeat = $.md5(postdata.password_new_repeat);
		$.xpost(jthis.attr('action'), postdata, function (code, message) {
			if (code == 0) {
				$.alert(message);
				jsubmit.button(message).delay(3000).button('reset');
			} else if (xn.is_number(code)) {
				alert(message);
				jsubmit.button('reset');
			} else {
				jthis.find('[name="' + code + '"]').alert(message).focus();
				jsubmit.button('reset');
			}
		});
		return false;
	});
	$('a[data-active="menu-my"]').addClass('active');
	$('a[data-active="my-password"]').addClass('active');
</script>